#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <strings.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>

int main(int argc ,char*argv[]){
	
	int sockfd;
	struct sockaddr_in addr;
	char buf[BUFSIZ] = {};
	socklen_t addrlen = sizeof(addr);

	if(argc < 3){
		fprintf(stderr, "%s<addr><port>", argv[0]);
		exit(EXIT_FAILURE);
	}
	/*create*/

	if( (sockfd = socket(AF_INET, SOCK_DGRAM, 0) ) < 0){
		perror("socket");
		exit(EXIT_FAILURE);
	}
	bzero(&addr, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons( atoi(argv[2]) );

	if(inet_aton(argv[1], &addr.sin_addr) == 0){
		fprintf(stderr, "Invalid address\n");
		exit(EXIT_FAILURE);
	}

	while(1){
		bzero(buf, BUFSIZ);
		printf("Input->");
		fgets(buf, BUFSIZ, stdin);
		sendto(sockfd, buf, strlen(buf), 0, (struct sockaddr *)&addr, addrlen);
	}

	close(sockfd);
	
	
	return 0;
}
